// pages/module/growth/growthUp/growthUp.js
import regeneratorRuntime from '../../../../utils/runtime.js';
import shareFun from '../../../../utils/shareFun.js';
import {uploadFile} from '../../../../utils/upload.js';
import { getData, setData, clearData, dataKey } from '../../../../utils/storage.js';
// import shareFun from '../../../../utils/shareFun.js';
import {
  robot, 
  submit,
} from '../../../../utils/imapi.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgCount:0,
    robotObj:{},
    is_show_active:0,
    countImg:'',
    nameImg:'',
    type:''
  },

  /**
   * 生命周期函数--监听页面加载 
   */
  onLoad: function (options) {
    shareFun.hidenShareMenu();
    this.goSign()
  },
  async goSign(){
    const {data} = await robot({robot_type:'1'})
    this.setData({
      robotObj:data
    })
  },
  async submit(){
    if(this.data.countImg == ''){
      wx.showToast({
        title: '请上传群主成员图片',
        icon: 'none',
        duration: 2000
       })
       return
    }
    if(this.data.nameImg == ''){
      wx.showToast({
        title: '请上传群主名称图片',
        icon: 'none',
        duration: 2000
       })
       return
    }
    const {data} = await submit({scm_type:1,robot_id:this.data.robotObj.id,img1:this.data.countImg,img2:this.data.nameImg,is_upgrade:1})
    /*wx.showToast({
      title: '提交成功，等待审核',
      icon: 'none',
      duration: 2000
     })*/

     if (data==undefined ||data==""){
      wx.showToast({
        title: '提交失败，请重试或联系客服!',
        icon: 'none',
        duration: 2000
       })
     }else{

      wx.navigateTo({
        url: '/pages/module/growth/growthUpStep2/growthUpStep2?scm_id='+ data,
      })


     }
  },
  upLoad(e){
    var that= this;
    //if(this.is_upload) return;
    var type = e.currentTarget.dataset.type
	this.is_upload = true
	//console.log('图片上传')
    this.is_upload = true
	console.log('图片上传')
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success:async function (res) {
		  //console.log(res)
			var zx=that.data.imgCount+1
			that.setData({
			  imgCount:zx
			})
	
		 //console.log(that.data.imgCount+1)
		  console.log(res)
        const tempFilePaths = res.tempFilePaths
        that.is_upload = false;
        if(type=='count'){
          that.setData({
            is_load1:true
          })
        } else {
          that.setData({
            is_loads:true
          })
        }
        const {data} = await uploadFile(tempFilePaths[0])
        if(type=='count'){
          that.setData({
            is_load1:false,
            countImg:data.indexOf('http')>-1?data:"http:"+data
          })
		  console.log("上传成功")
        } else {
          that.setData({
            is_load2:false,
            nameImg:data.indexOf('http')>-1?data:"http:"+data
          })
        }
        
      }
    })
  },
  copyed(e){
	  console.log(e.currentTarget.dataset.text)
	  wx.setClipboardData({
		  data:e.currentTarget.dataset.text,
		  success:function(res){
		  	// wx.showModal({
		  	// title: '提示',
		  	// content: '复制成功',
		  	// showCancel: false
		  	// });
		  }
	  })
  },
  see(e){
    console.log(e)
    this.setData({
      is_show_active:1,
      type:e.currentTarget.dataset.type
    })
  },
  closeDown1(){
    this.setData({
      is_show_active:0,
    })
  },
  navigate2(){
    this.setData({
      is_show_active:0
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})